package com.situ.cloud.service;

import cn.hutool.core.lang.Assert;
import com.situ.cloud.common.dto.UserDTO;
import com.situ.cloud.feign.UserFeign;
import com.situ.cloud.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserService implements UserDetailsService {

    @Autowired
    private UserFeign userFeign;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserDTO userDTO = userFeign.selectUser(username);
        Assert.isTrue(userDTO != null, "用户不存在");
        return new LoginUser(userDTO);
    }
}
